package com.service.impl;

import com.bean.entity.ParentsInfo;
import com.bean.pojo.PageAssistant;
import com.bean.vo.ParentsInfoVo;
import com.dao.ParentsInfoMapper;
import com.service.ParentsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 家长信息基础业务逻辑实现
 */
@Service
public class ParentsInfoServiceImpl implements ParentsInfoService {

    @Autowired
    private ParentsInfoMapper parentsInfoMapper;

    public int save(ParentsInfo t) throws Exception {
        return parentsInfoMapper.insert(t);
    }

    public int remove(ParentsInfo t) throws Exception {
        return parentsInfoMapper.delete(t);
    }

    public int modify(ParentsInfo t) throws Exception {
        return parentsInfoMapper.update(t);
    }

    public ParentsInfoVo unique(ParentsInfo t) throws Exception {

        List<ParentsInfoVo> parentsInfoVoList = parentsInfoMapper.select(t);

        return parentsInfoVoList.get(0);
    }

    public List<ParentsInfoVo> query(ParentsInfo t) {
        return parentsInfoMapper.select(t);
    }

    public PageAssistant<ParentsInfoVo> queryByPage(Map<String, Object> map, PageAssistant<ParentsInfoVo> pa) {
        //查询并设置总记录数
        pa.setCount(parentsInfoMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(parentsInfoMapper.selectByPage(map));
        return pa;
    }

    @Override
    public ParentsInfoVo login(ParentsInfo parentsInfo) throws Exception {

        List<ParentsInfoVo> parentsInfoVoList = parentsInfoMapper.select(parentsInfo);

        if (parentsInfoVoList.size()!=1)
            throw new Exception("登录失败，请输入正确的账号密码！");

        return parentsInfoVoList.get(0);
    }
}
